import { pinia, piniaPluginPersistedstate } from 'src/plugins/pinia/common';
import useSys from 'src/plugins/pinia/modules/sys';
import useUser from 'src/plugins/pinia/modules/user';
import useOrg from 'src/plugins/pinia/modules/org';

pinia.use(piniaPluginPersistedstate);

export const useStore = () => ({
	'sys': useSys(),
	'user': useUser(),
	'org': useOrg()
});

export const useDefines = () => ({
	useSys,
	useUser,
	useOrg
});

export function setupStore(app) {
	app.use(pinia);
}

/**
 * Usage
 *
  import {useStore} from 'src/pinia';
  const {sys} = useStore();
  console.log(sys.theme);
  console.log(sys.isCollapse);
  setInterval(() => {
    sys.$patch({ 'count': sys.count+1 });
    sys.$patch(state => {
      state.user = {};
    });
  },1000);
 */